﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using Autofac;
using Domain.IServices;
using Domain.Models;
using GitSyncApp.IServices;
using GitSyncApp.Views;
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace GitSyncApp
{
    public partial class App : Application
    {
        internal ILifetimeScope LifetimeScope;

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var builder = new ContainerBuilder();
            this.AddInfraService(builder);
            this.AddDomainServices(builder);
            this.AddAppServices(builder);
            LifetimeScope = builder.Build();

            // 开始任务调度
            LifetimeScope.Resolve<ISyncJobService>().StartAsync();
            // 显示主窗口
            LifetimeScope.Resolve<MainWindow>().Show();
        }

        private void Application_Exit(object sender, ExitEventArgs e)
        {
            LifetimeScope.Resolve<ISyncJobService>().StopAsync();
        }
    }
}
